﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <title>TrafficLight: src/main/java/com/stateforge/statemachine/examples/trafficlight/TrafficLight.java Source File</title>
    <link href="/Content/Help.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/tabs.css" rel="stylesheet" type="text/css" />
    <link href="/Content/css/doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div id="header">
        <img id="logo" alt="StateForge" src="/Content/Images/StateForgeLogo.png" />
        <div id="title">
            <h1>
                Examples using state machines generated by StateBuilderJava
            </h1>
            <h3>
                TrafficLight: src/main/java/com/stateforge/statemachine/examples/trafficlight/TrafficLight.java Source File
            </h3>
        </div>
        <div id="menucontainer">
            <ul id="menu">
                <li><a href="/">Home</a></li>
                <li><a href="/Home/Download">Downloads</a></li>
                <li><a href="/Help/state-machine-tools.aspx">Help</a></li>
                <li><a href="/Home/Faq">F.A.Q</a></li>
                <li><a href="/Home/About">Contact us</a></li>
            </ul>
        </div>
    </div>
<!-- Generated by Doxygen 1.7.4 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Packages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">src/main/java/com/stateforge/statemachine/examples/trafficlight/TrafficLight.java</div>  </div>
</div>
<div class="contents">
<a href="_traffic_light_8java.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="keyword">package </span>com.stateforge.statemachine.examples.trafficlight;
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="keyword">import</span> com.stateforge.statemachine.context.IContextEnd;
<a name="l00004"></a>00004 <span class="keyword">import</span> com.stateforge.statemachine.listener.ObserverConsole;
<a name="l00005"></a>00005 
<a name="l00010"></a><a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html">00010</a> <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html">TrafficLight</a>
<a name="l00011"></a>00011 {
<a name="l00012"></a><a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#a7d98a53ad90c329f4554a2892acbc929">00012</a>     <span class="keyword">private</span> <a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_light.html">Light</a> <a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#a7d98a53ad90c329f4554a2892acbc929">light</a>;
<a name="l00013"></a><a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#acd0b144a71aa0947d76dbaff14f0b6cf">00013</a>     <span class="keyword">private</span> TrafficLightContext <a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#acd0b144a71aa0947d76dbaff14f0b6cf">context</a>;
<a name="l00014"></a>00014     
<a name="l00015"></a><a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#a3ce47635d25314e35f0bdc52a5a98b8b">00015</a>     <span class="keyword">public</span> <a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#a3ce47635d25314e35f0bdc52a5a98b8b">TrafficLight</a>(){
<a name="l00016"></a>00016         this.<a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#a7d98a53ad90c329f4554a2892acbc929">light</a> = <span class="keyword">new</span> <a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_light.html">Light</a>();
<a name="l00017"></a>00017         this.<a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#acd0b144a71aa0947d76dbaff14f0b6cf">context</a> = <span class="keyword">new</span> TrafficLightContext(<a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#a7d98a53ad90c329f4554a2892acbc929">light</a>);
<a name="l00018"></a>00018         this.<a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#acd0b144a71aa0947d76dbaff14f0b6cf">context</a>.setObserver(ObserverConsole.getInstance());
<a name="l00019"></a>00019         this.<a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#acd0b144a71aa0947d76dbaff14f0b6cf">context</a>.setEndHandler(<span class="keyword">new</span> IContextEnd() {
<a name="l00020"></a>00020             <span class="keyword">public</span> <span class="keywordtype">void</span> end() {
<a name="l00021"></a>00021                 System.out.println(<span class="stringliteral">&quot;context has ended&quot;</span>);
<a name="l00022"></a>00022             }
<a name="l00023"></a>00023         });
<a name="l00024"></a>00024     }
<a name="l00025"></a>00025     
<a name="l00026"></a><a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#a9772f7a7d58cb56d0b986bc5a6f92312">00026</a>     <span class="keyword">public</span> <span class="keywordtype">void</span> <a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#a9772f7a7d58cb56d0b986bc5a6f92312">start</a>(){
<a name="l00027"></a>00027         this.<a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#acd0b144a71aa0947d76dbaff14f0b6cf">context</a>.enterInitialState();
<a name="l00028"></a>00028     }
<a name="l00029"></a>00029     
<a name="l00030"></a><a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#aa05fa775a78d82c398b276e8ce885815">00030</a>     <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#aa05fa775a78d82c398b276e8ce885815">main</a>( String[] args )
<a name="l00031"></a>00031     {
<a name="l00032"></a>00032         System.out.println( <span class="stringliteral">&quot;TrafficLight&quot;</span> );
<a name="l00033"></a>00033         <a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html">TrafficLight</a> trafficLight = <span class="keyword">new</span> <a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#a3ce47635d25314e35f0bdc52a5a98b8b">TrafficLight</a>();
<a name="l00034"></a>00034         trafficLight.<a class="code" href="classcom_1_1stateforge_1_1statemachine_1_1examples_1_1trafficlight_1_1_traffic_light.html#a9772f7a7d58cb56d0b986bc5a6f92312">start</a>();
<a name="l00035"></a>00035         
<a name="l00036"></a>00036         <span class="keywordflow">try</span> {
<a name="l00037"></a>00037             Thread.sleep(60000);
<a name="l00038"></a>00038         } <span class="keywordflow">catch</span> (InterruptedException e) {
<a name="l00039"></a>00039             <span class="comment">// TODO Auto-generated catch block</span>
<a name="l00040"></a>00040             e.printStackTrace();
<a name="l00041"></a>00041         }
<a name="l00042"></a>00042         System.out.println( <span class="stringliteral">&quot;TrafficLight ends&quot;</span> );
<a name="l00043"></a>00043     }    
<a name="l00044"></a>00044 }
</pre></div></div>
</div>
﻿<div id="footer">
    <hr />
    <p>
        Copyright &copy; 2011 StateForge.</p>
    <hr />
</div>
</body> </html> 
